import json


def read_file(file):
    with open(file, 'r', encoding='utf8', errors='ignore') as f:
        return f.read()


def read_file_lines(file):
    with open(file, 'r', encoding='utf8', errors='ignore') as f:
        return f.readlines()


def write_file(content, file):
    with open(file, "w", encoding='utf-8') as fw:
        fw.write(content)

def parse_json(file):
    with open(file, 'r', encoding='utf8', errors='ignore') as f:
        return json.load(f)


def write_json_str(json_str, file):
    data = json.loads(json_str)
    write_json(data, file)


def write_json(data, file):
    with open(file, "w", encoding='utf-8') as f:
        # print(type(data))
        json.dump(data, f, default=str, indent=4, sort_keys=True, ensure_ascii=False)
